package com.spelet.UIUtils;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.g2d.Sprite;
import com.spelet.Renderer;
import com.spelet.StaticTextures;
import com.spelet.screens.Screen;

public class FadeInTransitionEffect extends TransitionEffect {
	Color color = new Color();
	private Sprite wbgS;
	private float speed = 2.0f;

	public FadeInTransitionEffect(){
		alpha = 1.0f;
		wbgS = new Sprite(StaticTextures.wbg);
		wbgS.setColor(0f,0f,0f,1f);
		wbgS.setBounds(0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
	}
	
	@Override
	public void render(Screen current) {
		Renderer rdr = Renderer.getInstance();
		current.render();
		color.set(0f, 0f, 0f, getAlpha());
		wbgS.setColor(color);
		rdr.sb.setProjectionMatrix(rdr.mapUICam.combined);
		rdr.sb.begin();
		wbgS.draw(rdr.sb);
		rdr.sb.end();
	}
	
	@Override
	public void update(float delta){
		if(delta*speed>0.1f)
			delta = 0.1f/speed;
		alpha -= delta*speed;
		if(alpha<0f)
			alpha = 0f;
	}
	
	@Override
	public boolean isFinished()
	{
		return alpha <= 0.0f;
	}
}